<?php
require '../../../zb_system/function/c_system_base.php';

require '../../../zb_system/function/c_system_admin.php';

$zbp->Load();

$action = 'root';
if (!$zbp->CheckRights($action)) {
    $zbp->ShowError(6);
    die();
}

if (!$zbp->CheckPlugin('STACentre')) {
    $zbp->ShowError(68);
    die();
}

$blogtitle = '静态管理中心';

if (count($_GET) > 0) {
    if (function_exists('CheckIsRefererValid')) {
        CheckIsRefererValid();
    }
    if (GetVars('mak', 'GET') == '1') {
        @file_put_contents($zbp->path . '.htaccess', show_htaccess());
    } elseif (GetVars('mak', 'GET') == '2') {
        @file_put_contents($zbp->path . 'web.config', show_webconfig());
    } elseif (GetVars('mak', 'GET') == '3') {
        @file_put_contents($zbp->path . 'httpd.ini', show_httpini());
    }

    if (GetVars('del', 'GET') == '1') {
        @unlink($zbp->path . '.htaccess');
    } elseif (GetVars('del', 'GET') == '2') {
        @unlink($zbp->path . 'web.config');
    } elseif (GetVars('del', 'GET') == '3') {
        @unlink($zbp->path . 'httpd.ini');
    }

    $zbp->SetHint('good');

    Redirect('./list.php');
}

function show_htaccess()
{
    $ur = new UrlRule("");

    return $ur->Make_htaccess();
}

function show_httpini()
{
    $ur = new UrlRule("");

    return $ur->Make_httpdini();
}

function show_webconfig()
{
    $ur = new UrlRule("");

    return $ur->Make_webconfig();
}

function show_nginx()
{
    $ur = new UrlRule("");
    if (method_exists('UrlRule', 'Make_nginx')) {
        return $ur->Make_nginx();
    }
}

function show_lighttpd()
{
    $ur = new UrlRule("");
    if (method_exists('UrlRule', 'Make_lighttpd')) {
        return $ur->Make_lighttpd();
    }
}

if (!function_exists('BuildSafeURL')) {
    function BuildSafeURL($url, $appId = '')
    {
        global $zbp;
        if (substr($url, 0, 1) === '/') {
            $url = $zbp->host . $url;
        }

        return $url;
    }
}

require $blogpath . 'zb_system/admin/admin_header.php';
require $blogpath . 'zb_system/admin/admin_top.php';

$default_tab = strtolower($_SERVER["SERVER_SOFTWARE"]);
if (strpos($default_tab, 'apache') !== false) {
    $default_tab = 1;
} elseif (strpos($default_tab, 'iis/6') !== false) {
    $default_tab = 3;
} elseif (strpos($default_tab, 'nginx') !== false) {
    $default_tab = 4;
} elseif (strpos($default_tab, 'lighttpd') !== false) {
    $default_tab = 5;
} else {
    $default_tab = 2;
}
?>
<div id="divMain">

  <div class="divHeader">
    <?php echo $blogtitle; ?></div>
  <div class="SubMenu">
    <a href="main.php">
      <span class="m-left">配置页面</span>
    </a>
    <a href="list.php">
      <span class="m-left m-now">ReWrite规则</span>
    </a>
    <a href="help.php">
      <span class="m-right">帮助</span>
    </a>
  </div>
  <div id="divMain2">
    <?php if ($zbp->option['ZC_STATIC_MODE'] == 'ACTIVE') {
    ?>
    <p>动态模式下不生成静态规则.</p>
    <?php
} else {
        ?>
    <form id="edit" name="edit" method="post" action="#">
        <?php if (function_exists('CheckIsRefererValid')) {
            echo '<input type="hidden" name="csrfToken" value="' . $zbp->GetCSRFToken() . '">';
        } ?>
        <input id="reset" name="reset" type="hidden" value="" />

      <div class="content-box">
        <!-- Start Content Box -->

        <div class="content-box-header">
          <ul class="content-box-tabs">
            <li>
              <a href="#tab1" <?php echo $default_tab == 1 ? 'class="default-tab"' : ''; ?>>
                <span>Apache + .htaccess</span>
              </a>
            </li>
            <li>
              <a href="#tab2" <?php echo $default_tab == 2 ? 'class="default-tab"' : ''; ?>>
                <span>IIS 7及以上  + URL Rewrite Module</span>
              </a>
            </li>
            <li>
              <a href="#tab3" <?php echo $default_tab == 3 ? 'class="default-tab"' : ''; ?>>
                <span>IIS 6 + ISAPI Rewrite 2.X</span>
              </a>
            </li>
            <li>
              <a href="#tab4" <?php echo $default_tab == 4 ? 'class="default-tab"' : ''; ?>>
                <span>Nginx</span>
              </a>
            </li>
            <li>
              <a href="#tab5" <?php echo $default_tab == 5 ? 'class="default-tab"' : ''; ?>>
                <span>Lighttpd</span>
              </a>
            </li>
            <li>
              <a href="#tab6" <?php echo $default_tab == 6 ? 'class="default-tab"' : ''; ?>>
                <span>无组件</span>
              </a>
            </li>
          </ul>
          <div class="clear"></div>
        </div>
        <!-- End .content-box-header -->

        <div class="content-box-content">

          <div class="tab-content <?php echo $default_tab == 1 ? 'default-tab' : ''; ?>" style='border:none;padding:0px;margin:0;' id="tab1">
            <textarea style="width:99%;height:200px" readonly><?php echo htmlentities(show_htaccess())?></textarea>
            <hr/>
            <p>
              <input type="button" onclick="window.location.href='<?php echo BuildSafeURL('?mak=1'); ?>'" value="创建.htaccess" />
              &nbsp;&nbsp;&nbsp;&nbsp;
              <input type="button" onclick="window.location.href='<?php echo BuildSafeURL('?del=1'); ?>'" value="删除.htaccess" />
              <hr/>
              <span class="star">
                请在网站 <u>"当前目录"</u>
                创建.htaccess文件并把相关内容复制进去,也可以点击按钮生成.
              </span>
              <hr/>
              提示:ISAPI Rewrite 3也适用于此规则.
            </p>
          </div>

          <div class="tab-content <?php echo $default_tab == 2 ? 'default-tab' : ''; ?>" style='border:none;padding:0px;margin:0;' id="tab2">
            <textarea style="width:99%;height:400px" readonly><?php echo htmlentities(show_webconfig())?></textarea>
            <hr/>
            <p>
              <input type="button" onclick="window.location.href='<?php echo BuildSafeURL('?mak=2'); ?>'" value="创建web.config" />
              &nbsp;&nbsp;&nbsp;&nbsp;
              <input type="button" onclick="window.location.href='<?php echo BuildSafeURL('?del=2'); ?>'" value="删除web.config" />
              <hr/>
              <span class="star">
                请在网站 <u>"当前目录"</u>
                创建web.config文件并把相关内容复制进去,也可以点击按钮生成.
              </span>
            </p>
          </div>

          <div class="tab-content <?php echo $default_tab == 3 ? 'default-tab' : ''; ?>" style='border:none;padding:0px;margin:0;' id="tab3">
            <textarea id="ta_httpini" style="width:99%;height:200px" readonly><?php echo htmlentities(show_httpini())?></textarea>
            <hr/>
            <p>
              <input type="button" onclick="window.location.href='<?php echo BuildSafeURL('?mak=3'); ?>'" value="创建httpd.ini" />
              &nbsp;&nbsp;&nbsp;&nbsp;
              <input type="button" onclick="window.location.href='<?php echo BuildSafeURL('?del=3'); ?>'" value="删除httpd.ini" />
              <hr/>
              <span class="star">
                请在网站根目录创建httpd.ini文件并把相关内容复制进去,httpd.ini文件必须为ANSI编码,也可以点击按钮生成.
              </span>
              <hr/>
              提示:本规则用户可以加入自定义规则,将自己的目录或是文件排除过于广泛的重写之外.
              <hr/>
              提示:ISAPI Rewrite 3请按Apache规则生成.
            </p>
          </div>

          <div class="tab-content <?php echo $default_tab == 4 ? 'default-tab' : ''; ?>" style='border:none;padding:0px;margin:0;' id="tab4">
            <textarea style="width:99%;height:200px" readonly><?php echo htmlentities(show_nginx())?></textarea>
            <hr/>
            <p>
              &nbsp;&nbsp;&nbsp;&nbsp;
              <span class="star">
                修改nginx.conf,在  location / { }节点 或者是 location [安装目录名称] / { }（子目录安装）节点间加入上述规则.
              </span>
            </p>
          </div>

          <div class="tab-content <?php echo $default_tab == 5 ? 'default-tab' : ''; ?>" style='border:none;padding:0px;margin:0;' id="tab5">
            <textarea style="width:99%;height:250px" readonly><?php echo htmlentities(show_lighttpd())?></textarea>
            <hr/>
            <p>
              &nbsp;&nbsp;&nbsp;&nbsp;
              <span class="star">
                在主机控制面板的lighttpd静态规则中加入,或是修改/etc/lighttpd/lighttpd.conf加入上述规则.
              </span>
            </p>
          </div>

          <div class="tab-content <?php echo $default_tab == 6 ? 'default-tab' : ''; ?>" style='border:none;padding:0px;margin:0;' id="tab6">
            <p>你可以到主机的控制面板中找到类似“自定义404错误提示页面”等，填入：
            <code><?php echo str_replace("zb_users/plugin/STACentre/list.php", "index.php", $_SERVER['PHP_SELF']); ?></code></p>
            <p>如下图所示，这样你的网站将被Z-BlogPHP全面接管。此方案不需要伪静态组件，且发送的状态码符合规范。</p>
            <p><img src=""/></p>
            <p>IIS 7 / 8用户也可以创建<code>web.config</code>放在站点目录下，填入代码：</p>
            <textarea style="width:99%;height:250px" readonly>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;configuration&gt;
    &lt;system.webServer&gt;
        &lt;httpErrors errorMode="Custom"&gt;
            &lt;remove statusCode="404" subStatusCode="-1" /&gt;
            &lt;error statusCode="404" prefixLanguageFilePath="" path="/index.php" responseMode="ExecuteURL" /&gt;
        &lt;/httpErrors&gt;
        &lt;directoryBrowse enabled="true" /&gt;
    &lt;/system.webServer&gt;
&lt;/configuration&gt;
            </textarea>
            <hr/>
            <p>
              &nbsp;&nbsp;&nbsp;&nbsp;
              <span class="star">
                在主机控制面板的lighttpd静态规则中加入,或是修改/etc/lighttpd/lighttpd.conf加入上述规则.
              </span>
            </p>
          </div>

        </div>



      </div>
      <!-- End .content-box-content --> </div>

    <!-- End .content-box -->

    <hr/>
  </form>
    <?php
    }?>
  <script type="text/javascript">ActiveLeftMenu("aPluginMng");</script>
  <script type="text/javascript">AddHeaderIcon("<?php echo $bloghost . 'zb_users/plugin/STACentre/logo.png'; ?>");</script>
</div>

<?php
require $blogpath . 'zb_system/admin/admin_footer.php';

RunTime();
?>
